package com.example.javatwo.service.xs.dh;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.example.javatwo.mapper.xs.dh.KehuDao;
import com.example.javatwo.pojo.xs.dh.Kehu;
import com.example.javatwo.util.PageBead;

@Service
@Transactional(propagation = Propagation.REQUIRED)
public class KehuBiz implements IKehuBiz {

	@Autowired
	private KehuDao dao;

	public KehuDao getDao() {
		return dao;
	}

	public void setDao(KehuDao dao) {
		this.dao = dao;
	}

	@Override
	public PageBead findPage(Integer pageNum) {
		PageBead p = new PageBead();
		p.setTotalCount(dao.findCount());
		p.setCurrentPage(pageNum);
		p.setEveryPage(1);
		p.setData(dao.findPage(pageNum - 1));
		return p;
	}

	@Override
	public void delKehu(String id) {
		dao.delKehu(id);
	}

	@Override
	public int saveKehu(Kehu p) {
		Kehu x = dao.findKehu(p.getId());
		if ( x == null || "未审核".equals(x.getAddfield1())) {//验证该单据是否已存在||验证该单据状态
			if (x != null) {
				dao.delKehu(p.getId());
			}
			dao.saveKehu(p);
			return 0;
		} else {
			return 1;
		}

	}

	@Override
	public Kehu findKehu(String id) {
		return dao.findKehu(id);
	}

	@Override
	public int updateKehu(String id) {
		Kehu k = dao.findKehu(id);
		if ("未审核".equals(k.getAddfield1())) {
			dao.updateKehu(id);
			return 0;
		} else {
			return 1;
		}
	}

	@Override
	public void updateMoney(String id, Float money) {
		dao.updateMoney(id, money);
	}

}
